#ifndef DRAWLABEL_H
#define DRAWLABEL_H

#include <QObject>
#include <QWidget>
#include <QPen>
#include <QBrush>
#include <QMouseEvent>
#include <QPainter>
#include <QPaintEvent>
#include <QDebug>
#include <QWheelEvent>
#include <QThread>
#include <QMessageBox>
#include <QLabel>
#include <QFile>
#include <QPicture>
#include <QDir>
#include <QFileDialog>
#include <QVector>
#include <QtMath>
#include <QtGlobal>
#include <QScreen>
#include <QGuiApplication>

enum DrawType{
    DRAW_FREE=0,
    DRAW_LINE,
    DRAW_ARC,
    DRAW_RECT,
    DRAW_ARECT,
    DRAW_POLYGON,
    DRAW_ELLIPSE,
    DRAW_PEN,
    DRAW_BACK,
    DRAW_CLEAR,
    DRAW_SAVE,
    DRAW_ERASE

};

class DrawLabel : public QLabel
{
    Q_OBJECT
protected:
    void leaveEvent(QEvent *e);
    void focusOutEvent(QFocusEvent *event);
public:
    explicit DrawLabel(QWidget *parent = nullptr);
    void paintEvent(QPaintEvent *);
    bool eventFilter(QObject *obj, QEvent *event);	// 添加时间过滤器声明
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void wheelEvent(QWheelEvent *event);

    void setPenColor(QColor color);
    void setBrushColor(QColor color);
    void setBackColor(QColor color);
    void setPenSize(int size);
    void setDrawType(int type);
    void setPolygonType(int type);
    void setAutoFill(int a);

    void saveTmp();
    QFile restoreTmp();

signals:
    void signalClicked(int type, double x, double y);
public slots:
private:
    QColor penColor;
    QColor brushColor;
    QColor backColor;
    int penSize;
    int drawType=0;
    int polygonType;

    int startX, startY;
    int endX, endY, endPX, endPY;
    QVector<QPoint> points;
    QVector<QPoint> cubicPoints;
    QPolygon polyPoints;

    QPixmap pixmap;
    int tmpIdx=0;
    int backCnt=0;
    int undoCnt=0;
    bool autoFill=0;
    double scaleFactor=1;
};

#endif // DRAWLABEL_H
